//-----------------------------------------------------------------------
// <copyright file="TextMessageColor.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Live.Messenger
{
    using System;

    /// <summary>
    /// Represents a color.
    /// </summary>
    public sealed class TextMessageColor
    {
        private readonly MessengerEntity entity;

        internal TextMessageColor(object obj)
        {
            this.entity = new MessengerEntity(obj);
        }

        internal MessengerEntity Entity
        {
            get { return this.entity; }
        }

        /// <summary>
        /// Creates a <see cref="TextMessageColor"/> structure from the specified 8-bit color values (red, green, and blue).
        /// </summary>
        /// <param name="r">The red component.</param>
        /// <param name="g">The green component.</param>
        /// <param name="b">The blue component.</param>
        /// <returns></returns>
        public static TextMessageColor FromRgb(
            int r,
            int g,
            int b)
        {
            if ((r < Byte.MinValue) || (r > Byte.MaxValue))
            {
                throw ExceptionHelper.CreateArgumentOutOfRangeException("r");
            }

            if ((g < Byte.MinValue) || (g > Byte.MaxValue))
            {
                throw ExceptionHelper.CreateArgumentOutOfRangeException("g");
            }

            if ((b < Byte.MinValue) || (b > Byte.MaxValue))
            {
                throw ExceptionHelper.CreateArgumentOutOfRangeException("b");
            }

            return new TextMessageColor(MessengerEntity.Invoke(typeof(TextMessageColor), "FromRgb", r, g, b));
        }

        /// <summary>
        /// Gets the red component value of this <see cref="TextMessageColor"/> structure.
        /// </summary>
        public byte R
        {
            get { return this.entity.GetProperty<byte>("R"); }
        }

        /// <summary>
        /// Gets the green component value of this <see cref="TextMessageColor"/> structure.
        /// </summary>
        public byte G
        {
            get { return this.entity.GetProperty<byte>("G"); }
        }

        /// <summary>
        /// Gets the blue component value of this <see cref="TextMessageColor"/> structure.
        /// </summary>
        public byte B
        {
            get { return this.entity.GetProperty<byte>("B"); }
        }
    }
}